package utilities;

import java.io.FileInputStream;
import java.util.Properties;

/**
 * Globals class containing all properties read from the global properties file.
 * @author pcdejager
 *
 */
public final class Globals {
    /**
     * Constructor.
     * @throws Exception if properties cannot be loaded
     */
    private Globals() throws Exception {
        Properties properties = new Properties();
        FileInputStream inputStream = new FileInputStream(
                "src\\main\\resources\\global.properties");
        properties.load(inputStream);
        inputStream.close();

        String prop = properties.getProperty("Version");
        version = Integer.parseInt(prop);
    }

    /**
     * Get the singleton instance of the globals.
     * @return The instance of Globals
     */
    public static Globals getInstance() {
        if (instance == null) {
            try {
                instance = new Globals();
            } catch (Exception e) {
                instance = null;
            }
        }
        return instance;
    }

    /**
     * Get the version.
     * @return The version
     */
    public int getVersion() {
        return version;
    }

    /**
     * Singleton instance of the Globals class.
     */
    private static Globals instance = null;

    /**
     * The version read from properties.
     */
    private int version = 0;

}
